<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>kisebo: Código-Fonte de F:/Projetos/Rodrigo/kisebo/src/estruturas/ArvoreC.h</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Gerado por Doxygen 1.5.7.1 -->
<script type="text/javascript">
<!--
function changeDisplayState (e){
  var num=this.id.replace(/[^[0-9]/g,'');
  var button=this.firstChild;
  var sectionDiv=document.getElementById('dynsection'+num);
  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
    sectionDiv.style.display='block';
    button.src='open.gif';
  }else{
    sectionDiv.style.display='none';
    button.src='closed.gif';
  }
}
function initDynSections(){
  var divs=document.getElementsByTagName('div');
  var sectionCounter=1;
  for(var i=0;i<divs.length-1;i++){
    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
      var header=divs[i];
      var section=divs[i+1];
      var button=header.firstChild;
      if (button!='IMG'){
        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
        button=document.createElement('img');
        divs[i].insertBefore(button,divs[i].firstChild);
      }
      header.style.cursor='pointer';
      header.onclick=changeDisplayState;
      header.id='dynheader'+sectionCounter;
      button.src='closed.gif';
      section.id='dynsection'+sectionCounter;
      section.style.display='none';
      section.style.marginLeft='14px';
      sectionCounter++;
    }
  }
}
window.onload = initDynSections;
-->
</script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Página&nbsp;Principal</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Arquivos</span></a></li>
      <li><a href="dirs.html"><span>Diretórios</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>Lista&nbsp;de&nbsp;Arquivos</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_e5fb231306b426dbf7288f735af63cb9.html">src</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_f7619af0a658292424a6762d7a58c916.html">estruturas</a>
  </div>
</div>
<div class="contents">
<h1>ArvoreC.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef ARVOREC_H_</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define ARVOREC_H_</span>
<a name="l00003"></a>00003 <span class="preprocessor"></span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;cstdlib&gt;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00007"></a>00007 <span class="preprocessor">#include &lt;iomanip&gt;</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include &lt;exception&gt;</span>
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 <span class="keyword">using namespace </span>std;
<a name="l00011"></a>00011 
<a name="l00020"></a>00020 <span class="keyword">template</span>&lt;<span class="keyword">class</span> TCHV, <span class="keyword">class</span> TDADO&gt;
<a name="l00021"></a><a class="code" href="struct_no_c.html">00021</a> <span class="keyword">struct </span><a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC</a>
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023 
<a name="l00027"></a><a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">00027</a>         TCHV <a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a>;
<a name="l00028"></a>00028 
<a name="l00033"></a><a class="code" href="struct_no_c.html#c21d617a255311cec5bb7f877ce6a995">00033</a>         vector&lt;TDADO&gt; <a class="code" href="struct_no_c.html#c21d617a255311cec5bb7f877ce6a995">Valor</a>;
<a name="l00034"></a>00034 
<a name="l00038"></a><a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">00038</a>         <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> *<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a>, *dir;
<a name="l00039"></a>00039 
<a name="l00046"></a><a class="code" href="struct_no_c.html#3cbb74aa1e694707af1f9472848f1244">00046</a>         <a class="code" href="struct_no_c.html#3cbb74aa1e694707af1f9472848f1244" title="Construtor padrão. O Construtor já insere null em ambos os nós filhos,   para...">NoC</a>()
<a name="l00047"></a>00047         {
<a name="l00048"></a>00048                 <a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> = dir = NULL;
<a name="l00049"></a>00049         }
<a name="l00050"></a>00050 
<a name="l00060"></a><a class="code" href="struct_no_c.html#2cb03227f59c5d271732ad460caa2a1f">00060</a>         <a class="code" href="struct_no_c.html#3cbb74aa1e694707af1f9472848f1244" title="Construtor padrão. O Construtor já insere null em ambos os nós filhos,   para...">NoC</a>(TCHV c, TDADO v, <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV, TDADO&gt;</a> *e = NULL, <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV, TDADO&gt;</a> *d = NULL)
<a name="l00061"></a>00061         {
<a name="l00062"></a>00062                 <a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a> = c;
<a name="l00063"></a>00063                 <a class="code" href="struct_no_c.html#c21d617a255311cec5bb7f877ce6a995">Valor</a>.push_back(v);
<a name="l00064"></a>00064                 <a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> = e;
<a name="l00065"></a>00065                 dir = d;
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067 
<a name="l00068"></a>00068 };
<a name="l00069"></a>00069 
<a name="l00076"></a>00076 <span class="keyword">template</span>&lt;<span class="keyword">class</span> TCHV, <span class="keyword">class</span> TDADO&gt;
<a name="l00077"></a><a class="code" href="class_arvore_c.html">00077</a> <span class="keyword">class </span><a class="code" href="class_arvore_c.html" title="Classe para controlar a estrutura de árvore. Essa classe controla a criação da...">ArvoreC</a>
<a name="l00078"></a>00078 {
<a name="l00079"></a>00079 
<a name="l00080"></a>00080 <span class="keyword">private</span>:
<a name="l00081"></a>00081 
<a name="l00085"></a><a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">00085</a>         <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV, TDADO&gt;</a> *<a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a>;
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 <span class="keyword">public</span>:
<a name="l00088"></a>00088 
<a name="l00095"></a><a class="code" href="class_arvore_c.html#8d9900ac61433bc914b18de49b7947a2">00095</a>         <a class="code" href="class_arvore_c.html#8d9900ac61433bc914b18de49b7947a2" title="Construtor padrão. O contrutor já informa a raiz como null,   informando que quando...">ArvoreC</a>()
<a name="l00096"></a>00096         {
<a name="l00097"></a>00097                 <a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a> = NULL;
<a name="l00098"></a>00098         }
<a name="l00099"></a>00099 
<a name="l00106"></a><a class="code" href="class_arvore_c.html#9b4250941b363faa0afcfd050e65ba13">00106</a>         <span class="keyword">virtual</span> <a class="code" href="class_arvore_c.html#9b4250941b363faa0afcfd050e65ba13" title="Destrutor O destrutor limpa todos os itens da chave,   utilizando o método Remover...">~ArvoreC</a>()
<a name="l00107"></a>00107         {
<a name="l00108"></a>00108                 <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> *tmp = <a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a>;
<a name="l00109"></a>00109                 <span class="keywordflow">while</span>(tmp != NULL)
<a name="l00110"></a>00110                 {
<a name="l00111"></a>00111                         tmp = Remover(tmp-&gt;<a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a>, tmp);
<a name="l00112"></a>00112                 }
<a name="l00113"></a>00113         }
<a name="l00114"></a>00114 
<a name="l00121"></a><a class="code" href="class_arvore_c.html#fc936a4ac0502ae3b59863858acebf51">00121</a>         <span class="keywordtype">bool</span> <a class="code" href="class_arvore_c.html#fc936a4ac0502ae3b59863858acebf51" title="Verifica se a raiz da árvore é nula,   se for não existe registro gravado na árvore...">Vazia</a>()
<a name="l00122"></a>00122         {
<a name="l00123"></a>00123                 <span class="keywordflow">return</span> <a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a> == NULL;
<a name="l00124"></a>00124         }
<a name="l00125"></a>00125 
<a name="l00126"></a>00126 <span class="keyword">private</span>:
<a name="l00127"></a>00127 
<a name="l00128"></a>00128         <span class="comment">/*</span>
<a name="l00129"></a>00129 <span class="comment">         * @fn NoC&lt;TCHV, TDADO&gt; *Insere(TCHV chv, TDADO dado, NoC&lt;TCHV,TDADO&gt; *sub)</span>
<a name="l00130"></a>00130 <span class="comment">         * @brief Insere novos dados na árvore.</span>
<a name="l00131"></a>00131 <span class="comment">         * @param chv Chave do No.</span>
<a name="l00132"></a>00132 <span class="comment">         * @param dado Informação a ser armazenada.</span>
<a name="l00133"></a>00133 <span class="comment">         * @param sub No atual.</span>
<a name="l00134"></a>00134 <span class="comment">         */</span>
<a name="l00135"></a>00135         <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV, TDADO&gt;</a> *Insere(TCHV chv, TDADO dado, <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> *sub)
<a name="l00136"></a>00136         {
<a name="l00137"></a>00137 
<a name="l00138"></a>00138           <span class="keywordflow">if</span> ( sub == NULL )
<a name="l00139"></a>00139           {
<a name="l00140"></a>00140             sub = <span class="keyword">new</span> <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV, TDADO&gt;</a>( chv, dado );
<a name="l00141"></a>00141           }
<a name="l00142"></a>00142           <span class="keywordflow">else</span>
<a name="l00143"></a>00143           {
<a name="l00144"></a>00144 
<a name="l00145"></a>00145             <span class="keywordflow">if</span> ( chv &lt; sub-&gt;Chave )
<a name="l00146"></a>00146                sub-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> = Insere( chv, dado, sub-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> );
<a name="l00147"></a>00147 
<a name="l00148"></a>00148             <span class="keywordflow">if</span> ( chv &gt; sub-&gt;<a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a> )
<a name="l00149"></a>00149                 sub-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> = Insere( chv, dado, sub-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> );
<a name="l00150"></a>00150 
<a name="l00151"></a>00151             <span class="keywordflow">if</span> (chv == sub-&gt;<a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a>)
<a name="l00152"></a>00152                         sub-&gt;<a class="code" href="struct_no_c.html#c21d617a255311cec5bb7f877ce6a995">Valor</a>.push_back(dado);
<a name="l00153"></a>00153 
<a name="l00154"></a>00154             }
<a name="l00155"></a>00155 
<a name="l00156"></a>00156           <span class="keywordflow">return</span> sub;
<a name="l00157"></a>00157 
<a name="l00158"></a>00158         }
<a name="l00159"></a>00159 
<a name="l00160"></a>00160         <span class="comment">/*</span>
<a name="l00161"></a>00161 <span class="comment">         * @fn NoC&lt;TCHV,TDADO&gt; * Localizar( TCHV chv, NoC&lt;TCHV,TDADO&gt; * subarv )</span>
<a name="l00162"></a>00162 <span class="comment">         * @brief Localiza um No na árvore.</span>
<a name="l00163"></a>00163 <span class="comment">         * @param chv Chave do No.</span>
<a name="l00164"></a>00164 <span class="comment">         * @param subarv No atual.</span>
<a name="l00165"></a>00165 <span class="comment">         * @return No encontrado.</span>
<a name="l00166"></a>00166 <span class="comment">         */</span>
<a name="l00167"></a>00167         <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> * Localizar( TCHV chv, <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> * subarv )
<a name="l00168"></a>00168         {
<a name="l00169"></a>00169           <span class="keywordflow">if</span> ( subarv == NULL ) <span class="keywordflow">return</span> NULL;
<a name="l00170"></a>00170           <span class="keywordflow">else</span>
<a name="l00171"></a>00171           {
<a name="l00172"></a>00172             <span class="keywordflow">if</span> ( chv &lt; subarv-&gt;Chave )
<a name="l00173"></a>00173               <span class="keywordflow">return</span> Localizar( chv, subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> );
<a name="l00174"></a>00174             <span class="keywordflow">else</span>
<a name="l00175"></a>00175             {
<a name="l00176"></a>00176               <span class="keywordflow">if</span> ( chv &gt; subarv-&gt;<a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a> )
<a name="l00177"></a>00177                 <span class="keywordflow">return</span> Localizar( chv, subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> );
<a name="l00178"></a>00178               <span class="keywordflow">else</span>
<a name="l00179"></a>00179                 <span class="keywordflow">return</span> subarv; <span class="comment">// No Encontrado</span>
<a name="l00180"></a>00180             }
<a name="l00181"></a>00181           }
<a name="l00182"></a>00182         }
<a name="l00183"></a>00183 
<a name="l00184"></a>00184         <span class="comment">/*</span>
<a name="l00185"></a>00185 <span class="comment">         * @fn void Imprime( NoC&lt;TCHV,TDADO&gt; *subarv, int nv )</span>
<a name="l00186"></a>00186 <span class="comment">         * @brief Imprime todas as chaves encontradas na árvore.</span>
<a name="l00187"></a>00187 <span class="comment">         * @param subarv No atual.</span>
<a name="l00188"></a>00188 <span class="comment">         * @param nv campo para saber exatamente o espaço para a impressão.</span>
<a name="l00189"></a>00189 <span class="comment">         */</span>
<a name="l00190"></a>00190         <span class="keywordtype">void</span> <a class="code" href="class_arvore_c.html#57f1c2b0499cb9bea7ea52a918d7c29c" title="Imprime todas as chaves da árvore.">Imprime</a>( <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> *subarv, <span class="keywordtype">int</span> nv )
<a name="l00191"></a>00191         {
<a name="l00192"></a>00192           <span class="keywordflow">if</span> ( subarv == NULL ) <span class="keywordflow">return</span>;
<a name="l00193"></a>00193           <a class="code" href="class_arvore_c.html#57f1c2b0499cb9bea7ea52a918d7c29c" title="Imprime todas as chaves da árvore.">Imprime</a>( subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a>, nv + 1 );
<a name="l00194"></a>00194           cout &lt;&lt; setw(nv*5) &lt;&lt; <span class="stringliteral">" "</span> &lt;&lt; subarv-&gt;<a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a> &lt;&lt; endl;
<a name="l00195"></a>00195           <a class="code" href="class_arvore_c.html#57f1c2b0499cb9bea7ea52a918d7c29c" title="Imprime todas as chaves da árvore.">Imprime</a>( subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a>, nv + 1 );
<a name="l00196"></a>00196         }
<a name="l00197"></a>00197 
<a name="l00198"></a>00198         <span class="comment">/*</span>
<a name="l00199"></a>00199 <span class="comment">         * @fn NoC&lt;TCHV,TDADO&gt; *LocalizarMin( NoC&lt;TCHV,TDADO&gt; *subarv )</span>
<a name="l00200"></a>00200 <span class="comment">         * @brief Localiza o menor No dentro do No especifico.</span>
<a name="l00201"></a>00201 <span class="comment">         * @param subarv No onde queremos buscar o valor minimo.</span>
<a name="l00202"></a>00202 <span class="comment">         * @return O ménor No dentro do No informado.</span>
<a name="l00203"></a>00203 <span class="comment">         */</span>
<a name="l00204"></a>00204         <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> *LocalizarMin( <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> *subarv )
<a name="l00205"></a>00205         {
<a name="l00206"></a>00206                   <span class="keywordflow">if</span> ( subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> != NULL ) subarv = LocalizarMin( subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> );
<a name="l00207"></a>00207                   <span class="keywordflow">return</span> subarv;
<a name="l00208"></a>00208 
<a name="l00209"></a>00209         }
<a name="l00210"></a>00210 
<a name="l00211"></a>00211         <span class="comment">/*</span>
<a name="l00212"></a>00212 <span class="comment">         * @fn NoC&lt;TCHV,TDADO&gt; * Remover( TCHV chave, NoC&lt;TCHV,TDADO&gt; * subarv )</span>
<a name="l00213"></a>00213 <span class="comment">         * @brief Remover um item da árvore utilizando a chave.</span>
<a name="l00214"></a>00214 <span class="comment">         * @param chave Chave para buscar o item na árvore.</span>
<a name="l00215"></a>00215 <span class="comment">         * @param subarv No atual.</span>
<a name="l00216"></a>00216 <span class="comment">         * @return Retorna o No filho, caso o No tenha um.</span>
<a name="l00217"></a>00217 <span class="comment">         */</span>
<a name="l00218"></a>00218         <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> * Remover( TCHV chave, <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> * subarv )
<a name="l00219"></a>00219         {
<a name="l00220"></a>00220           <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> * tmp, * filho;
<a name="l00221"></a>00221           <span class="keywordflow">if</span> ( subarv == NULL )
<a name="l00222"></a>00222           {
<a name="l00223"></a>00223             <span class="keywordflow">return</span> NULL;
<a name="l00224"></a>00224           }
<a name="l00225"></a>00225           <span class="keywordflow">else</span>
<a name="l00226"></a>00226           {
<a name="l00227"></a>00227             <span class="keywordflow">if</span> ( chave &lt; subarv-&gt;Chave )
<a name="l00228"></a>00228             {
<a name="l00229"></a>00229               subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> = Remover( chave, subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> );
<a name="l00230"></a>00230             }
<a name="l00231"></a>00231             <span class="keywordflow">else</span>
<a name="l00232"></a>00232             {
<a name="l00233"></a>00233               <span class="keywordflow">if</span> ( chave &gt; subarv-&gt;<a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a> )
<a name="l00234"></a>00234               {
<a name="l00235"></a>00235                 subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> = Remover( chave, subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> );
<a name="l00236"></a>00236               }
<a name="l00237"></a>00237               <span class="keywordflow">else</span>
<a name="l00238"></a>00238               {
<a name="l00239"></a>00239                 <span class="keywordflow">if</span> ( subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> &amp;&amp; subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> )
<a name="l00240"></a>00240                 {
<a name="l00241"></a>00241                   tmp = LocalizarMin( subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> );
<a name="l00242"></a>00242                   subarv-&gt;<a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a> = tmp-&gt;<a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a>;
<a name="l00243"></a>00243                   subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> = Remover( subarv-&gt;<a class="code" href="struct_no_c.html#1a28d2490df8ca772b25acdd1c46237d">Chave</a>, subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> );
<a name="l00244"></a>00244                 }
<a name="l00245"></a>00245                 <span class="keywordflow">else</span>
<a name="l00246"></a>00246                 {
<a name="l00247"></a>00247                   tmp = subarv;
<a name="l00248"></a>00248                   <span class="keywordflow">if</span> ( subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> == NULL ) filho = subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a>;
<a name="l00249"></a>00249                   <span class="keywordflow">if</span> ( subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> == NULL ) filho = subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a>;
<a name="l00250"></a>00250                   <span class="keyword">delete</span> tmp;
<a name="l00251"></a>00251                   <span class="keywordflow">return</span> filho;
<a name="l00252"></a>00252                 }
<a name="l00253"></a>00253               }
<a name="l00254"></a>00254             }
<a name="l00255"></a>00255           }
<a name="l00256"></a>00256           <span class="keywordflow">return</span> subarv;
<a name="l00257"></a>00257         }
<a name="l00258"></a>00258 
<a name="l00259"></a>00259         <span class="comment">/*</span>
<a name="l00260"></a>00260 <span class="comment">         * @fn int Altura( NoC&lt;TCHV,TDADO&gt; * subarv )</span>
<a name="l00261"></a>00261 <span class="comment">         * @brief Quantos itens a árvore têm a partir do no informado.</span>
<a name="l00262"></a>00262 <span class="comment">         * @param subarv No atual.</span>
<a name="l00263"></a>00263 <span class="comment">         * @return a altura da árvore.</span>
<a name="l00264"></a>00264 <span class="comment">         */</span>
<a name="l00265"></a>00265         <span class="keywordtype">int</span> <a class="code" href="class_arvore_c.html#a9bd582693e8338c89584ce615904f2e" title="Imprime a quantidade de itens da árvore.">Altura</a>( <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> * subarv )
<a name="l00266"></a>00266         {
<a name="l00267"></a>00267           <span class="keywordtype">int</span> ae, ad;
<a name="l00268"></a>00268           <span class="keywordflow">if</span> ( subarv == NULL ) <span class="keywordflow">return</span> 0;
<a name="l00269"></a>00269           <span class="keywordflow">if</span> ( subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> == NULL &amp;&amp; subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> == NULL ) <span class="keywordflow">return</span> 1;
<a name="l00270"></a>00270           ae = <a class="code" href="class_arvore_c.html#a9bd582693e8338c89584ce615904f2e" title="Imprime a quantidade de itens da árvore.">Altura</a>( subarv-&gt;<a class="code" href="struct_no_c.html#6922357e093a4cb853a803f5ea9d1e75">esq</a> );
<a name="l00271"></a>00271           ad = <a class="code" href="class_arvore_c.html#a9bd582693e8338c89584ce615904f2e" title="Imprime a quantidade de itens da árvore.">Altura</a>( subarv-&gt;<a class="code" href="struct_no_c.html#ba08dd7deb046b1782ac88cb3f7a0217">dir</a> );
<a name="l00272"></a>00272           <span class="keywordflow">if</span> ( ae &gt; ad )
<a name="l00273"></a>00273                 <span class="keywordflow">return</span> ae + 1;
<a name="l00274"></a>00274           <span class="keywordflow">else</span>
<a name="l00275"></a>00275             <span class="keywordflow">return</span> ad + 1;
<a name="l00276"></a>00276         }
<a name="l00277"></a>00277 
<a name="l00278"></a>00278 <span class="keyword">public</span>:
<a name="l00279"></a>00279 
<a name="l00286"></a><a class="code" href="class_arvore_c.html#87678f7954718edc4e563498ee752f63">00286</a>         <span class="keywordtype">void</span> Insere(TCHV chave, TDADO dado)
<a name="l00287"></a>00287         {
<a name="l00288"></a>00288                 <a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a> = Insere(chave, dado, <a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a>);
<a name="l00289"></a>00289         }
<a name="l00290"></a>00290 
<a name="l00297"></a><a class="code" href="class_arvore_c.html#e8ba0bea20c5b550c72709e241cc2c55">00297</a>         vector&lt;TDADO&gt; <a class="code" href="class_arvore_c.html#e8ba0bea20c5b550c72709e241cc2c55" title="Obtem uma lista de valores em uma determinada chave.">Seleciona</a>(TCHV chave)
<a name="l00298"></a>00298         {
<a name="l00299"></a>00299 
<a name="l00300"></a>00300                 vector&lt;TDADO&gt; valores;
<a name="l00301"></a>00301 
<a name="l00302"></a>00302                 <a class="code" href="struct_no_c.html" title="Classe para controlar o No da ArvoreC. A classe armazena os dados do no atual e aponta...">NoC&lt;TCHV,TDADO&gt;</a> *tmp = Localizar(chave, <a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a>);
<a name="l00303"></a>00303 
<a name="l00304"></a>00304                 <span class="keywordflow">if</span>(tmp != NULL){
<a name="l00305"></a>00305                         valores = tmp-&gt;<a class="code" href="struct_no_c.html#c21d617a255311cec5bb7f877ce6a995">Valor</a>;
<a name="l00306"></a>00306                 }
<a name="l00307"></a>00307 
<a name="l00308"></a>00308                 <span class="keywordflow">return</span> valores;
<a name="l00309"></a>00309 
<a name="l00310"></a>00310         }
<a name="l00311"></a>00311 
<a name="l00316"></a><a class="code" href="class_arvore_c.html#57f1c2b0499cb9bea7ea52a918d7c29c">00316</a>         <span class="keywordtype">void</span> <a class="code" href="class_arvore_c.html#57f1c2b0499cb9bea7ea52a918d7c29c" title="Imprime todas as chaves da árvore.">Imprime</a>()
<a name="l00317"></a>00317         {
<a name="l00318"></a>00318                 <a class="code" href="class_arvore_c.html#57f1c2b0499cb9bea7ea52a918d7c29c" title="Imprime todas as chaves da árvore.">Imprime</a>(<a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a>,1);
<a name="l00319"></a>00319         }
<a name="l00320"></a>00320 
<a name="l00326"></a><a class="code" href="class_arvore_c.html#f0417f96065db048bf8b9c980d51feb2">00326</a>         <span class="keywordtype">void</span> <a class="code" href="class_arvore_c.html#f0417f96065db048bf8b9c980d51feb2" title="Deleta um determinado item pela chave informada.">Remove</a>(TCHV chave)
<a name="l00327"></a>00327         {
<a name="l00328"></a>00328                 <a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a> = Remover(chave, <a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a>);
<a name="l00329"></a>00329         }
<a name="l00330"></a>00330 
<a name="l00335"></a><a class="code" href="class_arvore_c.html#a9bd582693e8338c89584ce615904f2e">00335</a>         <span class="keywordtype">void</span> <a class="code" href="class_arvore_c.html#a9bd582693e8338c89584ce615904f2e" title="Imprime a quantidade de itens da árvore.">Altura</a>()
<a name="l00336"></a>00336         {
<a name="l00337"></a>00337                 <span class="keywordflow">return</span> <a class="code" href="class_arvore_c.html#a9bd582693e8338c89584ce615904f2e" title="Imprime a quantidade de itens da árvore.">Altura</a>(<a class="code" href="class_arvore_c.html#36ff0fe389e7ef504ae0afeaecdf4073">raiz</a>);
<a name="l00338"></a>00338         }
<a name="l00339"></a>00339 
<a name="l00340"></a>00340 };
<a name="l00341"></a>00341 
<a name="l00342"></a>00342 <span class="preprocessor">#endif </span><span class="comment">/*ARVOREC_H_*/</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Gerado em Wed Dec 3 04:35:41 2008 para kisebo por&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.7.1 </small></address>
</body>
</html>
